package com.zhj.goods.service;

import com.zhj.goods.mapper.StatisticMapper;
import com.zhj.goods.model.entity.*;
import com.zhj.goods.model.vo.FourBlockStat;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class StatisticService {

    @Resource
    private StatisticMapper mapper;

    //获取首页四个色块的数据，在线用户、今日采购额、今日销售额、今日毛利润
    public FourBlockStat getFourBlock() {

        FourBlockStat stat = new FourBlockStat();

        BigDecimal purchase = mapper.getPurchaseOrderDailyTotalPurchasePrice();
        BigDecimal sell = mapper.getSellOrderDailyTotalPurchasePrice();

        stat.setPurchase(purchase);
        stat.setSell(sell);
        stat.setProfit(sell.subtract(purchase));

        return stat;
    }

    //获取历史的每日采购额、销售额、毛利润
    public List<StatProfitTotal> getDailyProfitStat() {
        return mapper.searchTotalProfit();
    }

    //获取历史已完成的采购订单数、销售订单数
    public List<StatFinishOrder> getDailyFinishOrder() {
        return mapper.searchFinishOrder();
    }

    //获取每种商品的总采购总额、销售总额、总毛利
    public Collection<StatProfitGoods> getTotalProfitGoods() {

        Map<Integer, StatProfitGoods> map = new HashMap<>(8);
        List<StatProfitGoods> statProfitGoods = mapper.searchGoodsProfit();
        for (StatProfitGoods goods:
             statProfitGoods) {
            map.put(goods.getCid(),goods);
        }
        return map.values();
    }

    public List<SysCustomer> getCustomer(){
        List<SysCustomer> customer = mapper.getCustomer();
        return customer;
    }

    public List<SysSupply> getSupply(){
        List<SysSupply> supply = mapper.getSupply();
        return supply;
    }

}
